package request

type SysUserLoginRequest struct {
	Username string `json:"username" binding:"required" label:"用户名"`
	Password string `json:"password" binding:"required" label:"密码"`
}

func (sysUserLoginRequest SysUserLoginRequest) GetMessages() ValidatorMessages {
	return ValidatorMessages{
		"Username.required": "用户名不能为空",
		"Password.required": "密码不能为空",
	}
}

type SysUserCreateRequest struct {
	Username string `json:"username" binding:"required,min=2,max=20"`
	Password string `json:"password" binding:"required,min=6,max=20"`
	Nickname string `json:"nickname" binding:"required"`
	Email    string `json:"email" binding:"email"`
	Mobile   string `json:"Mobile"`
	Avatar   string `json:"avatar"`
	Status   int    `json:"status" binding:"oneof=0 1"`
	RoleIds  []uint `json:"role_ids"`
}

func (sysUserCreateRequest SysUserCreateRequest) GetMessages() ValidatorMessages {
	return ValidatorMessages{
		"Username.required": "用户名不能为空",
		"Username.min":      "用户名长度不能小于2",
		"Username.max":      "用户名长度不能大于20",
		"Password.required": "密码不能为空",
		"Password.min":      "密码长度不能小于6",
		"Password.max":      "密码长度不能大于20",
		"Nickname.required": "昵称不能为空",
		"Email.email":       "邮箱格式不正确",
		"Status.oneof":      "状态值不正确",
	}
}

type SysUserUpdateRequest struct {
	ID       uint   `json:"id" binding:"required"`
	Username string `json:"username"`
	Nickname string `json:"nickname"`
	Mobile   string `json:"mobile"`
	Avatar   string `json:"avatar"`
	Status   int    `json:"status" binding:"oneof=0 1"`
	RoleIds  []uint `json:"role_ids"`
	Email    string `json:"email" binding:"email"`
}

func (sysUserUpdateRequest SysUserUpdateRequest) GetMessages() ValidatorMessages {
	return ValidatorMessages{
		"ID.required":       "用户ID不能为空",
		"Username.min":      "用户名长度不能小于2",
		"Username.max":      "用户名长度不能大于20",
		"Nickname.required": "昵称不能为空",
		"Mobile.mobile":     "手机号格式不正确",
		"Status.oneof":      "状态值不正确",
	}
}

type SysUserListRequest struct {
	Username string `json:"username" form:"username"`
	Nickname string `json:"nickname" form:"nickname"`
	Mobile   string `json:"mobile" form:"mobile"`
	Email    string `json:"email" form:"email"`
	Status   *int   `json:"status" form:"status"`
	PageInfo
}

type PageInfo struct {
	Page     int `json:"page" form:"page" binding:"required,gte=1"`
	PageSize int `json:"page_size" form:"page_size" binding:"required,gte=1,lte=100"`
}

func (pageInfo PageInfo) GetOffset() int {
	return (pageInfo.Page - 1) * pageInfo.PageSize
}

type SysUserPasswordRequest struct {
	ID          uint   `json:"id" binding:"required" label:"用户ID"`
	OldPassword string `json:"old_password" binding:"required" label:"旧密码"`
	NewPassword string `json:"new_password" binding:"required" label:"新密码"`
}

type SysUserStatusRequest struct {
	ID     uint `json:"id" binding:"required"`
	Status *int `json:"status" binding:"required,oneof=0 1"`
}

func (sysUserStatusRequest SysUserStatusRequest) GetMessages() ValidatorMessages {
	return ValidatorMessages{
		"ID.required":    "用户ID不能为空",
		"Status.oneof":   "状态值不正确",
		"Status.require": "状态值不能为空",
	}
}
